package top.kaoshanji.p3ch11a;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 代码清单-p3ch11a-354页a：使用ReentrantLock类实现的生成唯一标识符的Java类
 * author kaoshanji
 * ^_^
 * create time 2025/2/4 14:19
 */
public class LockIdGenerator {

    private final ReentrantLock lock = new ReentrantLock();
    private int value = 0;
    public int getNext() {
        lock.lock();
        try {
            return value++;
        } finally {
            lock.unlock();
        }
    }

}
